﻿using MoonSharp.Interpreter.CoreLib;
using Projectsurviva;
using QFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Projectsurviva
{
    public class ExpUpgradeItem
    {
      public ExpUpgradeItem(bool isweapon) 
        {
            Isweapon = isweapon;

        }
        public bool Isweapon = false;

        public EasyEvent OnChanged = new EasyEvent();
        public bool Upgradefinish { get; set; } = false;
        public string key { get; set; }
        public string Description => mdescriptionFactory(currentlevel.Value);
       // public int price { get; set; }
        public int maxlevel { get; set; }
        public BindableProperty<int> currentlevel = new BindableProperty<int>(1);
        public BindableProperty<bool> Visible = new BindableProperty<bool>(false);
        public Func<int, string> mdescriptionFactory;
        //  public bool Visible
        public void Upgrade()
        {
            mOnupgrade?.Invoke(this,currentlevel.Value);
            OnChanged.Trigger();
            currentlevel.Value++;
            if(currentlevel.Value >10)
            {
            Upgradefinish = true;

            }
         //   CoinupdataSystem.OnCoinUpgradeSystemChanged.Trigger();
        }
        private Action<ExpUpgradeItem,int> mOnupgrade;

        private Func<ExpUpgradeItem, bool> mCondition;
        public bool ConditionCheck()
        {
            if (mCondition == null)
            {
                return !Upgradefinish;
            }
            else
            {
                return !Upgradefinish && mCondition.Invoke(this);
            }
        }
        public ExpUpgradeItem withkey(string Key)
        {
            key = Key;
            return this;
        }
        public ExpUpgradeItem withdescription(Func<int,string>  descriptionfactory)
        {
            mdescriptionFactory = descriptionfactory;
            return this;
        }
        public ExpUpgradeItem withAction(Action<ExpUpgradeItem,int> Onupgrade)
        {
            mOnupgrade = Onupgrade;
            return this;
        }
      
        public ExpUpgradeItem WithCondition(Func<ExpUpgradeItem, bool> condition)
        {
            mCondition = condition;
            return this;
        }
        public ExpUpgradeItem WithMaxlevel(int maxlevel)
        {
            this.maxlevel = maxlevel;
            return this;
        }
    }
}
